/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * $Id: IMUData.hpp,v 1.7 2009-05-13 07:18:16 amaula Exp $
 *
 * \file
 * \brief MaCI - IMU interface data encoder / decoder
 * \author Matthieu Myrsky <matthieu.myrsky@tkk.fi>
 */
#ifndef _MACI_IMUDATA_HPP_
#define _MACI_IMUDATA_HPP_
#include "MaCIData.hpp"
#include "IMUTypes.hpp"
#include <stdio.h>

namespace gim {
  namespace binbag{class CBinBag;}
}

namespace MaCI {
  namespace IMU {
    
    /** Data Encoder/Decoder for the IMU Interface.
     *
     * Contains the protocol encoder/decoder for the MaCI-IMU
     * interface
     */
    class CIMUData : public MaCI::CMaCIData
    {
    public:
      CIMUData(void);
      ~CIMUData();

      /** Copy constructor for IMUdata.
       */
      CIMUData(const CIMUData &aData);


      /** Assignment operator for Positiondata.
       *
       * Use this with care; each call to this function copies data, 
       * so avoid it if possible.
       */
      CIMUData &operator=(const CIMUData &aData);
      

      /** Decode a BinBag container as PositionData element.
       *
       */
      bool DecodeFrom(gim::binbag::CBinBag *aBinBag = NULL);
      

      /** Reset decoder/Encoder.
       *
       * Resets all fields, except leaves the current BinBag container
       * pointer intact.
       */
      void Reset();
      

      /** Set timestamp element.
       *
       * Sets timestamp element for the container.
       *
       * @param[in] aStamp      Reference to element to copy inside binbag.
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetTimestamp(const Common::TTimestamp &aStamp);


      /** Set Command element.
       *
       * Sets command element for the container.
       *
       * @param[in] aCommand    Reference to element to copy inside binbag.
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetCommand(const TCommand &aCommand);
      
      /** Set Acceleration element
       *
       * Sets acceleration3d element for the container.
       *
       * @param aAcceleration   Reference to element to copy inside binbag
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetAcceleration3d(const TAcceleration3d &aAcceleration);

      /** Set Rotation element
       *
       * Sets rotation3d element for the container.
       *
       * @param aAngularVelocity       Reference to element to copy inside binbag
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetAngularVelocity3d(const TAngularVelocity3d &aAngularVelocity);

      /** Set Angle element
       *
       * Sets angle3d element for the container.
       *
       * @param aAngle          Reference to element to copy inside binbag
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetAngle3d(const TAngle3d &aAngle);

      /** Set Quaternion element
       *
       * Sets quaternion3d element for the container.
       *
       * @param aQuaternion     Reference to element to copy inside binbag
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetQuaternion(const TQuaternion &aQuaternion);

      /** Set Orientation matrix element
       *
       * Sets orientationMatrix element for the container.
       *
       * @param aMatrix         Reference to element to copy inside binbag
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetOrientationMatrix(const TOrientationMatrix &aMatrix);

      /** Set Event Types
       *
       * Sets event types element for the container.
       *
       * @param aEventTypes     Reference to element to copy inside binbag
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetEventTypes(const TEventTypes &aEventTypes);

      /** Return Common::TTimestamp element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const Common::TTimestamp *GetTimestamp(void) const {
        return iTimestampPtr;
      }

      /** Return TAcceleration3d element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TAcceleration3d *GetAcceleration3d(void) const {
	return iAccelerationPtr;
      }

      /** Return TAngularVelocity3d element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TAngularVelocity3d *GetAngularVelocity3d(void) const{
	return iAngularVelocityPtr;
      }

      /** Return TAngle3d element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TAngle3d *GetAngle3d(void) const{
	return iAnglePtr;
      }

      /** Return TQuaternion element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TQuaternion *GetQuaternion(void) const{
	return iQuaternionPtr;
      }

      /** Return TOrientationMatrix element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TOrientationMatrix *GetOrientationMatrix(void) const{
	return iOrientationMatrixPtr;
      }

      /** Return TEventTypes element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TEventTypes *GetEventTypes(void) const{
        return iEventTypesPtr;
      }
      /** Return TCommand element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TCommand *GetCommand(void) const {
        return iCommandPtr;
      }

      /** Print.
       * 
       * \copydoc CMaCIData::Print()
       */
      void Print(const int level) const;

    protected:
    private:

      const Common::TTimestamp *iTimestampPtr;         ///< Pointer to timestamp if exists
      const TAcceleration3d *iAccelerationPtr;         ///< Pointer to acceleration if exists
      const TAngularVelocity3d *iAngularVelocityPtr;   ///< Pointer to rotation if exists
      const TAngle3d *iAnglePtr;                       ///< Pointer to angle if exists;
      const TQuaternion *iQuaternionPtr;               ///< Pointer to quaternion if exists;
      const TOrientationMatrix *iOrientationMatrixPtr; ///< Pointer to orientation 
                                                       /// matrix if exists
      const TEventTypes *iEventTypesPtr;               ///< Pointer to event types if exists
      const TCommand *iCommandPtr;                     ///< Pointer to command pointer if exists
    };
  }
}
#endif
